package twoD.hofem;

import gnu.jel.CompilationException;
import inf.math.UserFunction;

/**
 * UserFunctionRToR maps [a, b] according to the user defined mapping.
 * 
 * @author Team 5
 */

public class UserFunctionRToR implements FunctionRToR {

	private Interval domain_;
	private String s1_, s2_;
	private UserFunction f_, df_;

	/**
	 * The constructor uses UserFunction class
	 * " which is already implemented by Dr.Baitsch" such that it reads the String
	 * variable and interprets it as function please have a look at Java-how-to
	 * 
	 */

	public UserFunctionRToR(String s1, double a, double b) {

		s1_ = s1;
		domain_ = new Interval(a, b);
		try {
			UserFunction f = new UserFunction(s1_, "x");
			f_ = f;
		} catch (CompilationException e) {
			e.printStackTrace();
		}
	}

	/**
	 * The constructor uses UserFunction class
	 * " which already implemented by Dr.Baitsch" such that reads two String
	 * variables and interprets them as function and its derivative please have
	 * a look at Java-how-to
	 * 
	 */

	public UserFunctionRToR(String s1, String s2, double a, double b) {

		s1_ = s1;
		s2_ = s2;
		domain_ = new Interval(a, b);
		try {
			UserFunction f = new UserFunction(s1_, "x");
			f_ = f;
		} catch (CompilationException e) {
			e.printStackTrace();
		}
		try {
			UserFunction f1 = new UserFunction(s2_, "x");
			df_ = f1;
		} catch (CompilationException e) {
			e.printStackTrace();
		}
	}

	public double valueAt(double x) {

		return f_.valueAt(x);
	}

	public double derivativeAt(double x) {

		return df_.valueAt(x);
	}

	public Interval getDomain() {
		return domain_;
	}

	public int getP() {
		return -1;
	}

	public double[] getBreakpoints() {
		return null;
	}

}
